﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;

namespace Messenger.ViewModel
{
    public partial class StudentListViewModel : ObservableRecipient, IRecipient<ValueChangedMessage<string>>
    {
        public ObservableCollection<string> Students { get; } = new ObservableCollection<string>();

        [ObservableProperty]
        bool allowNew;

        partial void OnAllowNewChanged(bool value)
        {
            WeakReferenceMessenger.Default.Send(new ValueChangedMessage<bool>(value));
        }


        public void Receive(ValueChangedMessage<string> message)
        {
            Students.Add(message.Value);
        }
    }
}
